﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Miris.HumanMilkAnalyser.WPF.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using Miris.HumanMilkAnalyser.WPF.Model;

namespace Miris.HumanMilkAnalyser.WPF.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
            }
            else
            {
                SimpleIoc.Default.Register<IDataService, DataService>();
            }

            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<MainPageViewModel>();
            SimpleIoc.Default.Register<CreatePatientViewModel>();
            SimpleIoc.Default.Register<AnalysisResultMappingViewModel>();
            SimpleIoc.Default.Register<PatientQuickSearchViewModel>();
            SimpleIoc.Default.Register<AnalysisResultSummaryViewModel>();
            SimpleIoc.Default.Register<AnalysisReportViewModel>();
            SimpleIoc.Default.Register<UnassignedSampleNumberListViewModel>();
            SimpleIoc.Default.Register<DeviceUnassignedSampleNumberListViewModel>();
            SimpleIoc.Default.Register<PatientDataSearchViewModel>();
            SimpleIoc.Default.Register<DataManagementViewModel>();
            SimpleIoc.Default.Register<DiagnosticMessageReferenceSetupViewModel>();
            SimpleIoc.Default.Register<FurtherSuggestionViewModel>();
            SimpleIoc.Default.Register<BasicConfigurationViewModel>();
            SimpleIoc.Default.Register<RegistrationCodeViewModel>();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        /// <summary>
        /// Gets the MainPage property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainPageViewModel MainPage
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainPageViewModel>();
            }
        }

        /// <summary>
        /// Gets the CreatePatient property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public CreatePatientViewModel CreatePatient
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CreatePatientViewModel>();
            }
        }

        /// <summary>
        /// Gets the AnalysisResultMapping property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AnalysisResultMappingViewModel AnalysisResultMapping
        {
            get
            {
                return ServiceLocator.Current.GetInstance<AnalysisResultMappingViewModel>();
            }
        }

        /// <summary>
        /// Gets the PatientQuickSearch property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public PatientQuickSearchViewModel PatientQuickSearch
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PatientQuickSearchViewModel>();
            }
        }

        /// <summary>
        /// Gets the AnalysisResultSummary property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AnalysisResultSummaryViewModel AnalysisResultSummary
        {
            get
            {
                return ServiceLocator.Current.GetInstance<AnalysisResultSummaryViewModel>();
            }
        }

        /// <summary>
        /// Gets the AnalysisReport property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AnalysisReportViewModel AnalysisReport
        {
            get
            {
                return ServiceLocator.Current.GetInstance<AnalysisReportViewModel>();
            }
        }

        /// <summary>
        /// Gets the UnassignedSampleNumberList property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public UnassignedSampleNumberListViewModel UnassignedSampleNumberList
        {
            get
            {
                return ServiceLocator.Current.GetInstance<UnassignedSampleNumberListViewModel>();
            }
        }

        /// <summary>
        /// Gets the DeviceUnassignedSampleNumberListViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DeviceUnassignedSampleNumberListViewModel DeviceUnassignedSampleNumberList
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DeviceUnassignedSampleNumberListViewModel>();
            }
        }

        /// <summary>
        /// Gets the PatientDataSearch property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public PatientDataSearchViewModel PatientDataSearch
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PatientDataSearchViewModel>();
            }
        }

        /// <summary>
        /// Gets the DiagnosticMessageReferenceSetup property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DiagnosticMessageReferenceSetupViewModel DiagnosticMessageReferenceSetup
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DiagnosticMessageReferenceSetupViewModel>();
            }
        }

        /// <summary>
        /// Gets the DataManagement property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public DataManagementViewModel DataManagement
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DataManagementViewModel>();
            }
        }

        /// <summary>
        /// Gets the FurtherSuggestion property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public FurtherSuggestionViewModel FurtherSuggestion
        {
            get
            {
                return ServiceLocator.Current.GetInstance<FurtherSuggestionViewModel>();
            }
        }

        /// <summary>
        /// Gets the BasicConfiguration property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public BasicConfigurationViewModel BasicConfiguration
        {
            get
            {
                return ServiceLocator.Current.GetInstance<BasicConfigurationViewModel>();
            }
        }

        /// <summary>
        /// Gets the RegistrationCode property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public RegistrationCodeViewModel RegistrationCode
        {
            get
            {
                return ServiceLocator.Current.GetInstance<RegistrationCodeViewModel>();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            // Unregister will call Cleanup in ViewModelBase.
            SimpleIoc.Default.Unregister<MainViewModel>();
            SimpleIoc.Default.Unregister<MainPageViewModel>();
            SimpleIoc.Default.Unregister<AnalysisResultMappingViewModel>();
            SimpleIoc.Default.Unregister<PatientQuickSearchViewModel>();
            SimpleIoc.Default.Unregister<AnalysisResultSummaryViewModel>();
            SimpleIoc.Default.Unregister<AnalysisReportViewModel>();
            SimpleIoc.Default.Unregister<UnassignedSampleNumberListViewModel>();
            SimpleIoc.Default.Unregister<DeviceUnassignedSampleNumberListViewModel>();
            SimpleIoc.Default.Unregister<PatientDataSearchViewModel>();
            SimpleIoc.Default.Unregister<DataManagementViewModel>();
            SimpleIoc.Default.Unregister<DiagnosticMessageReferenceSetupViewModel>();
            SimpleIoc.Default.Unregister<FurtherSuggestionViewModel>();
            SimpleIoc.Default.Unregister<BasicConfigurationViewModel>();
            SimpleIoc.Default.Unregister<RegistrationCodeViewModel>();
        }
    }
}